import { useCallback, useMemo } from "react";

const useLocalStorage = (key, defaultValue) => {
  const values = useMemo(() => JSON.parse(localStorage.getItem(key)) || defaultValue, [key, defaultValue]);

  const setValues = useCallback((data) => localStorage.setItem(key, JSON.stringify(data)), [key]);

  return [values, setValues];
};

export default useLocalStorage;
